package com.shiguiwu.springmybatis.spring.property;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.util.stream.Stream;

/**
 * @description: 修改配置，动态生效
 * @author: stone
 * @date: Created by 2021/4/6 19:56
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.spring.property
 */
public class RefreshScopeTests {

    public static void main(String[] args) {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
        //讲自定义作用域注册到容器中
        context.getBeanFactory().registerScope(BeanMyScope.scopeName, new BeanMyScope());

        context.register(Person.class);
        context.refresh();

        Person bean = context.getBean(Person.class);
        System.out.println("person的class对象：" + bean.getClass());

        System.out.println("多次调用username的效果-----------------------");

        Stream.of(1,2,3).forEach(e -> {
            System.out.println(bean.getUsername() + "-----------------------");

        });
    }
}
